package com.foolishbird.sdk.ui.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.foolishbird.sdk.params.bean.FloatMenu;
import com.foolishbird.sdk.params.bean.FloatUserInfo;
import com.foolishbird.sdk.ui.assist.OnFinishActivityListener;
import com.foolishbird.sdk.utils.MyFragmentManger;
import com.foolishbird.sdk.utils.ResUtils;


public class FloatPhonebindedFragment extends BaseHttpFragment implements View.OnClickListener {


//    private LinearLayout phoneLayout,realnameLayout,versionLayout,pwdLayout;
    private TextView titleTxt;
    private ImageView backView;
    TextView phoneText,kefuTxt;
    Button confirmBtn;

    public static final FloatPhonebindedFragment newInstance(Bundle bundle) {
        FloatPhonebindedFragment fragment = new FloatPhonebindedFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        int resource = ResUtils.getLayoutIdentifier(getActivity(), "fb_fragment_float_binded_phone");
        View contentView =inflater.inflate(resource,null);
        titleTxt = contentView.findViewById(getViewIdentifier("fb_fragment_float_title"));
        titleTxt.setText("手机绑定");
        backView = contentView.findViewById(getViewIdentifier("fb_fragment_login_back"));
        backView.setOnClickListener(this);
        confirmBtn = contentView.findViewById(getViewIdentifier("fb_fragment_phone"));
        phoneText = contentView.findViewById(getViewIdentifier("float_binded_phone"));
        kefuTxt = contentView.findViewById(getViewIdentifier("float_bind_kefu"));
        kefuTxt.setOnClickListener(this);
        confirmBtn = contentView.findViewById(getViewIdentifier("fb_fragment_login_login_btn"));
        confirmBtn.setOnClickListener(this);
        FloatUserInfo info = (FloatUserInfo)getArguments().getSerializable("userInfo");
        phoneText.setText(info.getPhone());
        return contentView;

    }

    private FloatUserInfo userInfo;



    @Override
    public void onClick(View view) {
        if(view == backView){
//            if(userInfo!=null&&!TextUtils.isEmpty(userInfo.getId_number())){
//
//            }
            MyFragmentManger.getInstance().goBack(this);
        }else if (view == confirmBtn){
            MyFragmentManger.getInstance().gotoFragment(FloatPhoneChangeBindFragment.newInstance(null));
        }else if(view == kefuTxt){
            FloatMenu menu = new FloatMenu();
            menu.setType(1);
            menu.setIdentifier("customer");
            MyFragmentManger.getInstance().goDefaultFragment(menu);
        }

//        OnFinishActivityListener listener = getOnFinishActivityListener();
//        if (listener != null) {
//            listener.doFinishActivity(this);
//        }
    }

    private OnFinishActivityListener getOnFinishActivityListener() {
        if (!isNullContext()) {
            Activity activity = getActivity();
            if (activity instanceof OnFinishActivityListener) {
                return (OnFinishActivityListener) activity;
            }
        }
        return null;
    }
}
